package com.keke.select.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.keke.select.service.SelectService;
import com.keke.utils.SystemException;

@WebServlet("/api/getCptts")
public class GetCptts extends HttpServlet {
	private static final long serialVersionUID = 1L;
	private static SelectService service = new SelectService();

	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String key = req.getParameter("key");
		String data;
		PrintWriter out =  resp.getWriter();
		System.out.println("GetCptts");
		try {
			data = service.getCpttsJsonStr(key);
			out.print("{\"isOk\":true,\"data\":"+data+"}");
		} catch (SystemException e) {
			String err = e.toString().split(": ")[1];
			out.print("{\"isOk\":false,\"data\":\""+err+"\"}");
		}
	}

	public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doGet(req, resp);
	}
}